package org.lex.expression;

public class MyStringReader {
	public static final int EOF = -1;

	private String source = null;
	private int length = 0;
	private int index = 0;

	public MyStringReader() {
		this("");
	}

	public MyStringReader(String source) {
		if (null == source)
			source = "";
		this.setSource(source);
	}

	public void setSource(String source) {
		this.source = source;
		this.length = source.length();
		this.index = 0;
	}

	public int read() {
		// reach end of source
		if (index >= length)
			return EOF;
		return source.charAt(index++);
	}

	public void pushback(int ch) {
		if (ch != EOF)
			this.index--;
	}
}
